package main

/**
闭包
 */
import "fmt"

func intSeq() func() int {
	i := 0
	return func() int {
		i++
		return i
	}
}

func initSeq2() func() int{
	i := 0
	seq := func() int {
		i++
		return i
	}
	return seq
}

func main() {

	nextInt := intSeq()

	fmt.Println(nextInt())
	fmt.Println(nextInt())
	fmt.Println(nextInt())

	newInts := intSeq()
	fmt.Println(newInts())

	newInts2 := initSeq2()
	fmt.Println(newInts2())
	fmt.Println(newInts2())
	fmt.Println(newInts2())
	fmt.Println(newInts2())
	fmt.Println(newInts2())
}
